{template 'header'}
<ul class="nav nav-tabs">
	<li><a href="{php echo $this->createWebUrl('listcaiji');}" name="topbtn">采集库列表</a></li>
</ul>
<style>
.table td span{display:inline-block;margin-top:4px;}
.table td input{margin-bottom:0;}
th{
	text-align: center !important;
}
td{
	text-align: center !important;
}
.red{color:red;font-weight:bold}
</style>
{if $op == 'display'}
<div class="main">

<a class="btn btn-sm btn-danger" href="javascript:importrow1({$row['id']})"><i class="fa fa-mail-forward"></i> 导入高佣商品</a>

<a class="btn btn-sm btn-info" href="javascript:importrow2({$row['id']})"><i class="fa fa-mail-forward"></i> 导入通用商品</a>


<a href="javascript:;" class="btn btn-sm btn-success mutadd">批量添加到商品库</a>

<a href="{php echo $this->createWebUrl('listdoc')}" class="btn btn-sm btn-warning">从目录中读取文件</a>

<a href="#delallbtn" class="btn btn-sm btn-link">到底部↓↓↓</a>

<br><br>
<form action="" method="post" class="form-horizontal" role="form">
	<div style="padding:15px;background: white;">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
				    <th style="width:3em;">
                        <input type="checkbox" id="checkall"/>
                    </th>
					<th style="width:100px;">序号</th>
					<th style="width:auto;text-align: left !important;">商品信息</th>
					<th style="width:100px">状态</th>
					<th style="width:200px">修改/删除</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $item}
				<tr>
				    <td><input type="checkbox" name="ids[]" value="{$item['id']}" style="font-size:10px"/></td>
					<td><input type="text" name="displayorder[{$item['id']}]" value="{$item['displayorder']}"  style="width:50px;font-size:10px;text-align: center;"></td>
					<td style="text-align: left !important;width:100%;">
					名称：<label class="label label-success">{$item['itemid']}</label>&nbsp;{$item['title']}<br>
					口令：{$item['itemtkl']}<br>
					短链：{$item['itemsurl']}<br>
					<!--长链：{$item['itemurl']}<br>-->
					{if $item['itemyhj_tit']!='无'}优惠卷：{$item['itemyhj_tit']}<br>
					优惠卷-口令：{$item['itemyhj_tkl']}<br>
					<!--优惠卷-链接：{$item['itemyhj_url']}<br>-->{/if}
					</td>
					<td data-id='{$item["id"]}'>{if $item['status']}<label class="label label-success">启用</label>{else}<label class="label label-default">禁用</label>{/if}</td>
					
					<td>
						<!--a href="{php echo $this->createWebUrl('listcaiji', array('op' => 'post', 'id' => $item['id']))}" title="编辑" class="btn btn-sm btn-default"><i class="fa fa-edit"></i></a-->
						<a onclick="return confirm('删除此商品，确认吗？'); return false;" href="{php echo $this->createWebUrl('listcaiji', array('op' => 'del','id' => $item['id']))}" title="删除" class="btn btn-sm btn-danger"><i class="fa fa-remove"></i></a>
					</td>
				</tr>
				{/loop}

                <tr>
				    <th style="width:3em;">
                        <input type="checkbox" id="checkallbottom"/>
                    </th>
					
				</tr>

				<tr>
	                <td colspan="7" style="text-align: left !important;">
	                	<input name="token" type="hidden" value="{$_W['token']}" />
	                    <input type="submit" class="btn btn-primary" name="submit" value="提交排序" />

						<a data-href="{php echo $this->createWebUrl('listcaiji',array('op'=>'delall'))}" href="javascript:;" class="btn btn-danger mutdelete" id="delallbtn" name="delallbtn">删除选中</a>

						<a href="javascript:;" class="btn btn-info mutadd">批量添加到商品库</a>

						<a href="#topbtn" class="btn btn-sm btn-link">到顶部↑↑↑</a>
	                </td>
	            </tr>


			</tbody>
			
		</table>
		{$pager}
	</div>
</form>
</div>
<style>
	.masklayer{ display: none; width: 100%; height: 100%; position: fixed; z-index: 1000; top: 0px; left: 0px; background: rgba(0,0,0,0.7);}
	.mask{ display: none; width: 460px; height: auto; overflow: hidden; position: fixed; z-index: 2000; left: 50%; margin-left: -230px; background: #fff; top: 20%;}
	.mask .title{ width: 100%; height: 40px; line-height: 40px; background:#467ab3; position: relative; z-index: 10;}
	.mask .title span{ margin-left: 15px; color: #fff; font-size: 14px;}
	.mask .title .close{ width: 40px; height: 40px; position: absolute; display: block; top: 7px; right: -15px;color:#fff; z-index: 20;}
	.maskMain{  padding: 0px; height: auto; overflow: hidden; text-align: center; padding-bottom: 30px;}
	.maskMain a{ width: 40%; height: 46px; line-height: 46px; text-align: center; display: inline-block; background: #467ab3; color: #fff; border: 1px solid #000; margin: 30px 15px 0px 15px;}
</style>
<div class="masklayer" onclick="javascript:close1();" style="display: none;" id="masklayer1"></div>
<div class="mask maskOuter" style="display: none;" id="mask1">
			<p class="title">
				<span>批量导入商品（高佣）</span>
				<em class="close" onclick="javascript:close1();">X</em>
			</p>
			<div class="maskMain">
				<form style="display: inline-block;width: 400px;" action="{php echo $this->createWebUrl('importxls1',array('op'=>('music')))}" method="post" enctype="multipart/form-data" class="form-inline">
				<input type="hidden" id="rowid" name="rowid" value=""/>
				<input type="file" name='txtfile1' class="form-control">
				<button class="btn btn-info" style="margin-left:5%;" type="submit">导入</button>
				</form>
			</div>
</div>

<div class="masklayer" onclick="javascript:close1();" style="display: none;" id="masklayer2"></div>
<div class="mask maskOuter" style="display: none;" id="mask2">
			<p class="title">
				<span>批量导入商品（通用）</span>
				<em class="close" onclick="javascript:close1();">X</em>
			</p>
			<div class="maskMain">
				<form style="display: inline-block;width: 400px;" action="{php echo $this->createWebUrl('importxls2',array('op'=>('music')))}" method="post" enctype="multipart/form-data" class="form-inline">
				<input type="hidden" id="rowid" name="rowid" value=""/>
				<input type="file" name='txtfile2' class="form-control">
				<button class="btn btn-info" style="margin-left:5%;" type="submit">导入</button>
				</form>
			</div>
</div>


<div id="modal-module-menus-cheat"  class="modal fade" tabindex="-1">
        <div class="modal-dialog" style='width: 520px;'>
            <div class="modal-content">
                <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>请选择栏目</h3></div>
                <div class="modal-body">
                
				{loop $cate $i}
				   <a data-id="{$i['id']}" data-href="{php echo $this->createWebUrl('listcaiji',array('op'=>'addall'))}" href="javascript:;" class="btn btn-info mutaddok" style="margin:5px 5px;">{$i['name']}</a>
                {/loop}

                </div>
            </div>
        </div>
</div>

<script>
function importrow1(rowid){
	$('#rowid').val(rowid);
	$("#mask1").fadeIn(500);
	$("#masklayer1").fadeIn(500);
}
function importrow2(rowid){
	$('#rowid').val(rowid);
	$("#mask2").fadeIn(500);
	$("#masklayer2").fadeIn(500);
}
function close1(){
	$(".maskOuter").fadeOut(500);
	$(".masklayer").fadeOut(500);
}
</script>
<script>
require(['util'],function(util){
$('.mutdelete').click(function(){
            var url = $(this).data('href');
            var ids = [];
            var idss = [];
            $('input:checkbox[name="ids[]"]').each(function() {
                var _that = $(this)[0];
                if(_that.checked){
                    ids = ids.concat($(this).val());
                }else{
                    idss = idss.concat($(this).val());
                }
            });
            console.log(ids);
            if(confirm("您确定要删除么？")){
                $.post(url,{ids:ids},function(data){
                    util.message("删除成功","{php echo $_W['siteurl']}",'success');
                },'json');
            }
        });


$('.mutadd').click(function(){

$('#modal-module-menus-cheat').modal();

});

$('.mutaddok').click(function(){
            var url = $(this).data('href');
            var ids = [];
            var idss = [];
			var cateid = $(this).data('id');
            $('input:checkbox[name="ids[]"]').each(function() {
                var _that = $(this)[0];
                if(_that.checked){
                    ids = ids.concat($(this).val());
                }else{
                    idss = idss.concat($(this).val());
                }
            });
			
            console.log(cateid);
            if(confirm("您确定要导入么？")){
                $.post(url,{ids:ids,cateid:cateid},function(data){
                    util.message("导入成功","{php echo $_W['siteurl']}",'success');
                },'json');
            }
        });


});

$("#checkall").click(function(){
            console.log('checkall');
            $('input[name="ids[]"').each(function(){
                var _that = $(this)[0];
                if(_that.checked){
                    _that.checked = false;
                }else{
                    _that.checked = true;
                }
            });
        });


$("#checkallbottom").click(function(){
            $("#checkall").click();
        });


$('table label').click(function(){
	var label = $(this);
	$.ajax({
		url:'{php echo $this->createWebUrl("listcaiji",array("op"=>"status"))}',
		type:'post',
		data:{id:label.parent().attr('data-id')},
		success:function(status){
			if(status == '1'){
				if(label.hasClass('label-success')){
					label.removeClass('label-success').addClass('label-default');
					label.text('禁用');
				}else{
					label.removeClass('label-default').addClass('label-success');
					label.text('启用');
				}
			}
		}
	});
});
</script>
{elseif $op == 'post'}
<div class="panel panel-info">
		<div class="panel-body">
			<form action="" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="id" value="{$item[id]}">
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">商品名称</label>
				<div class="col-sm-4">
					<input class="form-control" required="required" name="title" type="text" value="{$item['title']}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">排序</label>
				<div class="col-sm-4">
					<input class="form-control" name="displayorder" type="number" min="0" value="{$item['displayorder']}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">状态</label>
				<div class="col-sm-4">
					<label><input type="radio" name="status" checked="checked" value="0"> 禁用</label>
					<label style="margin-left: 10px;"><input type="radio" name="status" {if $item['status']}checked="checked"{/if} value="1"> 启用</label>
				</div>
			</div>
			<button type="submit" class="btn btn-primary" name="submit" value="提交">保存</button>
			<input type="hidden" name="token" value="{$_W['token']}" />
			</form>
	</div>
</div>
{/if}
{template 'footer'}
